// var  = "https://hazardouswastewxapi.cnsbdz.com" //公共请求头
// const BASE_URL = import('../config/index')
import {
	requestUrl
} from "./config.js"
var TOKEN = uni.getStorageSync('TOKEN') //TOKEN

const http = (options) => {

	return new Promise((resolve, reject) => {
		uni.request({
			// url: "http://erecord.cnsbdz.com:8080/smartERecordWXApi" + options.url,
			url: requestUrl + options.url,
			method: options.method || 'POST',
			data: options.data || {},
			timeout: 50000,
			header: {
				"Content-type": "application/json",
				'token': uni.getStorageSync('TOKEN') || '',
			},
			success: (res) => {
				if (res.data.code == 0) {
					resolve(res.data)
				} else {
					if (res.data.msg) {
						uni.showToast({
							title: res.data.msg,
							mask: true,
							icon: 'none'
						})
					} else {
						uni.showToast({
							title: '网络错误',
							mask: true,
							icon: 'error'
						})
					}
				}
			},
			fail(err) {
				uni.showToast({
					title: err.errMsg,
					mask: true,
					icon: 'none'
				})

			}
		})



	})
}








export default http